
<?
	  include("/inc/header.html") {}
    ?>
    <link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
 	<script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
	<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>
    <div id="page-wrapper" style="margin-left: 0px; ">

	<!--BEGIN CONTENT-->
	<div class="page-content"
		style="min-height: auto;padding-bottom: 20px; height: 610px; overflow: auto;">

		<div class="row mbl">

<div class="panel ">
	<div class="panel-body pan" >

		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-left:-13px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">用户名
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="username" type="text" class="form-control" onchange="verifyName(this.value)" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-left:-18px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">密码
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="password" type="password" class="form-control" value="" />
					</div>
				</div>
			</div>
		</div>


		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-left:-13px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">真实姓名</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="realname" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-left:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">昵称
					 </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nickname" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
		</div>

        <div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-left:-13px;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">联系电话
				<span class='require'></span></label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="telephone" type="text" class="form-control" />
					</div>
				</div>
			</div>
		<div class="row" style="margin-bottom: 10px;">
		<div class="col-lg-6"
				style="width: 400px; float:left; margin-left:-20px;display:inline;">
				<label for="firstname" class="col-md-3 control-label">手机号
				<span class='require'>*</span></label>
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="mobilephone" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">用户类型
				<span class='require'>*</span></label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="type" class="form-control">
							<option value="2">机构下的个人用户</option>
						</select>
					</div>
				</div>
			</div>
		</div>


		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">头像</label>
				<div class="col-md-9">
					<div>
						<div style= "display:inline " id="single_"></div>
							<div style="display:inline " id="single"></div>
							<input type="button" class="btn btn-primary" onclick="upImages()" value="上传图片"  />
							<textarea id="uploadImage" name="uploadImage"></textarea>
							<input id="avatarImg" type="hidden" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">秘钥</label>
							<div class="col-md-9">
								<div class="input-group input-group-sm mbs">
									<input id="keys" type="text"  class="form-control" disabled="true" /> 
									<span class="input-group-btn">
									<button onclick="createKeys()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">生成秘钥</button>
									</span> 
								</div>
							</div>
						</div>
			<!--					<div class="col-md-6">
						<div class="form-group">
								<div style= "display:inline " id="single"></div>
							 	<input type="button" onclick="upload(1)"  class="btn btn-primary" value="选择图片"  />
								<input type="hidden" id="singlePhone_"  /> 
								<input type="hidden" name="as" id="onePhone_" /> 
						</div>
					</div>
					  -->

		</div>
		<div class="row" style=" margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">专业</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="profession" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
					style="width: 400px; float:left; display:inline;">
					<label for="inputUsername" class="col-md-3 control-label">邮箱
					</label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="email" type="text" class="form-control" />
						</div>
					</div>
				</div>
		</div>
		<div class="row" style=" margin-bottom: 10px;">
					<div class="col-md-12"
							style="width: 780px;margin-left:-2px; float:left; display:inline;">
							<label for="firstname" class="col-md-3 control-label">地址
							</label>
							<div class="col-md-12">
						<div class="input-icon">
							<input id="address" type="text" class="form-control" />
					</div>
				</div>
		    </div>
		</div>
		<div class="row" style=" margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">证件类型</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="certificateType" class="form-control">
							<option value="0">身份证</option>
							<option value="1">军官证</option>
							<option value="2">护照</option>
							<option value="3">其他</option>
						</select>
					</div>
				</div>
			</div>

			
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">证件号</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="certificateNumber" class="form-control" />
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">工作单位</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="workunit" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;  float:left; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">职称
					</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="title" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			</div>
			<div class="row" style="margin-bottom: 10px;">
				<div class="col-lg-6"
					style="width: 400px; float:left; margin-right:-20px; display:inline;">
					<label for="inputUsername" class="col-md-3 control-label">状态
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<select id="status" class="form-control">
								<option value="0">启用</option>
								<option value="1">禁用</option>
							</select>
						</div>
					</div>
				</div>
		<div class="col-lg-6"
				style="width: 400px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">学历</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="education" onchange="onPanduan(this.value);"
							type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			</div>
			<div class="row" style="margin-bottom: 10px;">
				<div class="col-lg-6"
					style="width: 400px; float:left; margin-right:-20px; display:inline;">
					<label for="inputUsername" class="col-md-3 control-label">性别
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<select id="gender" class="form-control">
								<option value="0">女</option>
								<option value="1">男</option>
								<option value="2">未知</option>
							</select>
						</div>
					</div>
				</div>
				<div class="col-lg-6"
					style="width: 400px; float:left;  margin-right:-20px; display:inline;">
					<label for="inputUsername" class="col-md-3 control-label">年龄
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="age" 
								type="text" class="form-control" value="" />
						</div>
					</div>
				</div>
			</div>
			<div style="margin-bottom: 10px; width: 750px;">
					<label for="inputUsername" class="col-md-3 control-label">研究领域
						<span class='require'></span> </label>
					<div class="col-md-12">
						<div class="input-icon">
							<textarea id="researchField"  rows="2" cols="20" class="form-control" ></textarea> 
						</div>
					</div>
				</div>
			<div class="row" style="margin-bottom: 10px;">
				<div class="col-lg-6"
					style="width: 400px; float:left;  margin-right:-20px; display:inline;">
					<label for="inputUsername" class="col-md-3 control-label">有效期</label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="validity" type="text" class="form-control" value="" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" />
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</div>
</div>

<script>


function getQueryString(name) { 
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r != null) return unescape(r[2]); return null; 
	} 
	var winName=getQueryString("winName");
	
var indexid = window.parent.window[winName].getlay();
var memberid = window.parent.window[winName].getindex();
var _editor;
	$(function() {
	
		if(indexid != 0){
			$.ajax({
			type : "post",
			url : "./organizationUserUpdate.do",
			data : {
				"id" : indexid,
			},
			dataType : "json",
			async : false,
			success : function(data) {
				$("#username").val(data[0].username);
				memberid=data[0].memberId;
				$("#password").val(data[0].password);
				 document.getElementById('password').disabled = true;
				$("#nickname").val(data[0].nickname);
				//$("#memberId").val(data[0].memberId);
				$("#realname").val(data[0].realname);
				$("#type").val(data[0].type);
				$("#createTime").val(data[0].createTime);
				$("#createIpAddress").val(data[0].createIpAddress);
				$("#avatarImg").val(data[0].avatarImg);
				$("#single").html("<img src='"+data[0].avatarImg+"' width='30' height='30'/>");
				$("#email").val(data[0].email);
				$("#education").val(data[0].education);
				$("#profession").val(data[0].profession);
				$("#researchField").val(data[0].researchField);
				$("#status").val(data[0].status);
				$("#mobilephone").val(data[0].mobilephone);
				$("#workunit").val(data[0].workunit);
				$("#title").val(data[0].title);
				$("#certificateType").val(data[0].certificateType);
				$("#certificateNumber").val(data[0].certificateNumber);
				$("#gender").val(data[0].gender);
				$("#age").val(data[0].age);
				$("#keys").val(data[0].keys);
				$("#address").val(data[0].address);
				$("#telephone").val(data[0].telephone);
				$("#validity").val(data[0].validity);

			},
			error : function(data) {
				alert("请求失败");
			}
		});
		}
		 _editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#avatarImg").val(urlPath);
						$("#single").html("<img src='"+urlPath+"' width='30' height='30' />");
	  	 			}
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	
		   	 });
	   }); 
	});
	//上传图片
	function upImages() {
		var myFiles = _editor.getDialog("insertimage");
	  		myFiles.open();
	   
	}
	function Page() {
		if ($.trim($("#username").val()).length < 1) {
			alert('用户名不能为空！');
			return null;
		}
		if ($.trim($("#password").val()).length < 1) {
			alert('密码不能为空！');
			return null;
		}else{
			var reg =new RegExp("[\u4e00-\u9fa5]");
			if(reg.test($("#password").val())){
		      	alert('密码只可由数字和字母组成！');
		      	$("#password").val("");
				return null;
		    }
		}
		if ($.trim($("#type").val()).length < 1) {
			alert('用户类型不能为空！');
			return null;
		}
		if ($.trim($("#mobilephone").val()).length < 1) {
			alert('手机号不能为空！');
			return null;
		} 
		if ($.trim($("#status").val()).length < 1) {
			alert('请选择状态！');
			return null;
		}
		if ($.trim($("#age").val()).length < 1) {
			alert('请填写您的年龄！');
			return null;
		}
		var text=$.trim($("#email").val()); //    
       	var re =/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
       	if ($.trim($("#email").val()).length >0) {
			if (!re.test(text)) {
				alert('邮箱格式不正确！');
				return null;
			}
		}
		
		var telephonetext=$.trim($("#mobilephone").val()); //    
       	var telephonere =/^[1][3,4,5,7,8][0-9]{9}$/;
       	if ($.trim($("#mobilephone").val()).length >0) {
			if (!telephonere.test(telephonetext)) {
				alert('手机号格式不正确！');
				return null;
			}
		}
		/*
		if ($.trim($("#validity").val()).length < 1) {
			alert('请选择有效期！');
			return null;
		}
		*/
		$.ajax({
			type : "post",
			url : "./userAddUpdate.do",
			data : {
				"id" : indexid,
				"memberId" : memberid,
				"username" : $("#username").val(),
				"password" : $("#password").val(),
				"nickname" : $("#nickname").val(),
				"realname" : $("#realname").val(),
				"mobilephone" : $("#mobilephone").val(),
				"email" : $("#email").val(),
				"avatarImg" : $("#avatarImg").val(),
				"createTime" : $("#createTime").val(),
				"status" : $("#status").val(),
				"education" : $("#education").val(),
				"profession" : $("#profession").val(),
				"researchField" : $("#researchField").val(),
				"workunit" : $("#workunit").val(),
				"title" : $("#title").val(),
				"certificateType" : $("#certificateType").val(),
				"certificateNumber" : $("#certificateNumber").val(),
				"type" : $("#type").val(),
				"age" : $("#age").val(),
				"gender" : $("#gender").val(),
				"keys" : $("#keys").val(),
				"address" : $("#address").val(),
				"telephone" : $("#telephone").val(),
				"validity" : $("#validity").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
			window.parent.window[winName].demo1(1);
				var index = parent.layer.getFrameIndex(window.name);
				
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}

	function newdate() {
		$.getJSON('./newDate.do', {}, function(res) {
			$("#createTime").val(res.date);
		});
	};
		function createKeys(){
		$.ajax({
			type : "post",
			url : "createKeys.do",
			dataType : "json",
			success : function(data) {
				$("#keys").val(data[0].keys);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	 //验证用户名是否重复
 function verifyName(memberName){
	$.ajax({
		type : "post",
		url : "verifyMemberName.do",
		data : {
			"memberName" : memberName,
			"type" : 0,
		},
		async : false,
		dataType : "json",
		success : function(data) {
			if(data[0].count != '0'){
				$("#username").val("");
				layer.msg('用户名已存在!请重新输入！');
			}
		},
		error : function(data) {
			alert("请求失败");
		}
	});
 }
</script>


